package com.atguigu.yygh.hosp.service.impl;

import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.common.handler.YyghException;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.hosp.mapper.HospitalSetMapper;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class HospitalSetServiceImpl
        extends ServiceImpl<HospitalSetMapper, HospitalSet>
        implements HospitalSetService {

    /**
     * 获取签名key
     * @param hoscode
     * @return 跟据hoscode查询签名信息
     */
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);  //严格匹配数据库字段
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper); //唯一的数据，selectOne 只查一条
        if(hospitalSet==null){ //如果不加判断，空值情况下直接空指针
            throw new YyghException(20001,"获取签名失败");
        }
        return hospitalSet.getSignKey();//不为空直接返回
    }

    //根据hoscode查询医院
    @Override
    public HospitalSet getByHoscode(String hoscode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));
        return hospitalSet;
    }


}
